(function(angular) {
    "use strict";
    /*

    */
    var service_module = angular.module("cloapCertificateApp.service"),
        deployment_service_url = "http://10.79.122.13:5000",
        deployment_cloap_url = "http://10.79.122.13:8080",
        
        develop_service_url = "http://127.0.0.1:5000",
        develop_cloap_url = "http://127.0.0.1:8080",

        service_url = develop_service_url,
        service_preffix = "/cloap/app/paper_app",
        cloap_url = develop_cloap_url;

    /* 登记证书 */
    service_module.factory("Certificate", function($resource) {
        return $resource(service_url + service_preffix + "/paper_registers/:certificate_id", {
            certificate_id: "@id"
        }, {
            update: {method: "PUT"}
        });
    });

    /* 证书类型 */
    service_module.factory("CertificateType", function($resource) {
        return $resource(service_url + service_preffix + "/paper_types/:certificate_type_id", {
            certificate_type_id: "@id"
        }, {
            update: {method: "PUT"},
            toggle: {
                method: "POST",
                url: service_url + service_preffix + "/paper_types/:certificate_type_id/toggle",
                isArray: false
            }
        });
    });


    /* 统计分析 */
    service_module.factory("Statistics", function($resource) {
        return $resource(service_url + service_preffix + "/:certificate_id", {
            certificate_id: "@id"
        }, {
            // 持证率分析
            query_ratio: {
                method: "GET",
                url: service_url + service_preffix + "/query/ratio",
                isArray: true
            },

            // 持证缺失分析
            query_lost: {
                method: "GET",
                url: service_url + service_preffix + "/query/lost",
                isArray: true
            },

            // 持证到期分析
            query_duedate: {
                method: "GET",
                url: service_url + service_preffix + "/query/duedate",
                isArray: true
            }

        });
    });

    /* 审查机构 */
    service_module.factory("CheckOrgan", function($resource) {
        return $resource(service_url + service_preffix + "/managers/:manager_id", {
            manager_id: "@id"
        }, {
            update: {method: "PUT"},
            toggle: {
                method: "POST",
                url: service_url + service_preffix + "/managers/:manager_id/toggle",
                isArray: false
            }
        });
    });

    /* 机构控管 */
    service_module.factory("OrganControl", function($resource) {
        return $resource(service_url + service_preffix + "/organ_registers/:organ_control_id", {
            organ_control_id: "@id"
        }, {
            update: {method: "PUT"}
        });
    });

    /* 持证要求 */
    service_module.factory("CertificateRequire", function certificateRequireFactory($resource) {
        return $resource(service_url + service_preffix +
                         "/paper_requires/:certificate_require_id", {
            certificate_require_id: "@id"
        }, {
            update: {method: "PUT"}
        });
    });

 /* cloap */

    /* 机构 */
    service_module.factory("Organ", function($resource) {
        return $resource(cloap_url + "/role/organ/:organ_id", {organ_id: "@id"}, {
            all: {
                method: "GET",
                url: cloap_url + "/role/organ/all",
                isArray: true
            }
        });
    });

    /* 员工 */
    service_module.factory("Employee", function($resource) {
        return $resource(cloap_url + "/role/users/:user_id", {user_id: "@id"}, {
            all: {
                method: "GET",
                url: cloap_url + "/role/user/all",
                isArray: true
            }
        });
    });

    service_module.factory("Position", function($resource) {
        return $resource(cloap_url + "/role/position/:position_id", {position_id: "@id"}, {
            all: {
                method: "GET",
                url: cloap_url + "/role/position/all",
                isArray: true
            }
        });
    });
}(angular));
